home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- ** GAL.c
- *******************************************************************************
- **
- ** description:
- **
- ** This file containts routines for reading and programming GALs
- **
- ******************************************************************************/
-
-
-
-
-
- /********************************* includes **********************************/
-
- #include <exec/types.h>
- #include <intuition/intuition.h>
- #include <ctype.h>
- #include <stdio.h>
- #include <string.h>
-
- #include <proto/locale.h>
-
- #include "GALer.h"
- #include "Localize.h"
-
-
-
-
-
- /********************************** defines **********************************/
-
-
-
-
-
- /******************************** functions **********************************/
-
-
-
-
-
- /******************************** variables **********************************/
-
- extern struct AppString { LONG as_ID;
- STRPTR as_Str;
- };
-
- extern struct AppString AppStrings[];
-
- extern char path[];
- extern int GALType, JedecSecurity, JedecGALType;
- extern struct JedecStruct Jedec;
- extern struct Configuration Config;
- extern struct Catalog *catalog;
-
-
- int MaxFuseAdr, SigAdr, RowSize, XORSize;
-
- extern long prog_time, bulk_time;
-
- struct JedecStruct Jedec2;
-
-
- UBYTE SignatureTxt[] = "Signature: $00 $00 $00 $00 $00 $00 $00 $00 : XXXXXXXX";
- UBYTE PTTxt[] = "PT: 0000000000000000000000000000000000000000000000000000000000000000";
- UBYTE ConTxt[] = "XOR(n): 00000000 SYN: 0 AC0: 0";
- UBYTE AC1Txt[] = "AC1(n): 00000000";
- UBYTE XOR10Txt[] = "XOR(23-14): 0000000000";
- UBYTE SYN10Txt[] = "SYN(23-14): 0000000000";
-
-
- UBYTE *CmpText1, *CmpText2, *CmpText3, *CmpText4;
-
-
-
-
-
-
-
- /******************************************************************************
- ** ProgramGAL()
- *******************************************************************************
- ** input: none
- ** output: none
- **
- ** remarks: This function does read a JEDEC file. According to this JEDEC
- ** file a GAL is programmed.
- ******************************************************************************/
-
- void ProgramGAL(void)
- {
-
- if (GALTypeRequest(AppStrings[MSG_GAL_PROG].as_Str))
- {
- if (MyFileReq(AppStrings[MSG_LOADJED].as_Str, ".jed", YES, LOAD))
- {
-
- if (!(GetJedec((UBYTE *)&path[0])))
- {
-
- if (GALType != JedecGALType) /* does selected GAL and JEDEC */
- { /* match? */
- JedecError(25, NO);
- return;
- }
-
-
- if (ReadGALParameter(YES)) /* read the GAL's parameters */
- return;
-
- if (!ProgJedecToGAL(PROGGAL))
- {
-
- if (JedecSecurity) /* is security bit of the JEDEC */ /*war im Jedec-File das Sec.*/
- SetSecurity(NO); /* file set? */
-
- TxtRequest(AppStrings[MSG_GALPROGED].as_Str,
- AppStrings[MSG_CONT_GAD].as_Str, NULL);
- }
- else
- return;
-
- }
- }
- }
- }
-
-
-
-
-
- /******************************************************************************
- ** CopyGAL()
- *******************************************************************************
- ** input: none
- ** output: none
- **
- ** remarks: copy GAL
- ******************************************************************************/
-
- void CopyGAL(void)
- {
- int flag;
-
- if (GALTypeRequest(AppStrings[MSG_COPY_GAL].as_Str))
- {
-
- if (ReadGALParameter(YES)) /* read GAL parameters */
- return;
-
- PrintText(AppStrings[MSG_READING_GAL].as_Str, 1);
-
- ReadGALToJedec(); /* read source GAL */
-
- PrintText(AppStrings[MSG_LOWER_OK].as_Str, 0);
-
-
- flag = 0;
-
- for (;;)
- {
-
- if (flag)
- if (!TxtRequest(AppStrings[MSG_COPY_AGAIN].as_Str,
- AppStrings[MSG_CONT_GAD].as_Str,
- AppStrings[MSG_CANCEL_GAD].as_Str))
- break;
-
- flag = 1;
-
- TxtRequest(AppStrings[MSG_INS_DEST_GAL].as_Str,
- AppStrings[MSG_CONT_GAD].as_Str, NULL);
-
- if (!ReadGALParameter(YES)) /* read GAL parameters and */
- ProgJedecToGAL(COPYGAL); /* program the destination GAL */
-
- }
- }
- }
-
-
-
-
-
- /******************************************************************************
- ** Leertest() -- means something like EmptyTest()
- *******************************************************************************
- ** input: none
- ** output: none
- **
- ** remarks: checks whether or not the GAL is erased
- ******************************************************************************/
-
- void Leertest(void)
- {
- int result;
-
- if (GALTypeRequest(AppStrings[MSG_BLANK_TEST].as_Str))
- {
- if (ReadGALParameter(YES)) /* get GAL's parameters */
- return;
-
- PrintText(AppStrings[MSG_EXE_BLANK_TEST].as_Str ,1);
-
- result = CheckGAL();
-
- PrintText(AppStrings[MSG_READY].as_Str, 0);
-
- if (result)
- TxtRequest(AppStrings[MSG_NOT_BLANK].as_Str,
- AppStrings[MSG_CONT_GAD].as_Str, NULL);
- else
- TxtRequest(AppStrings[MSG_BLANK].as_Str,
- AppStrings[MSG_CONT_GAD].as_Str, NULL);
- }
- }
-
-
-
-
-
- /******************************************************************************
- ** CheckGAL()
- *******************************************************************************
- ** input: none
- ** output: 0: GAL is empty
- ** 1: logic matrix is empty
- ** 2: logic matrix is empty, but not the other parts
- **
- ** remarks: check whether the GAL is empty or not
- ** The GAL parameters must be read before calling this function!
- ******************************************************************************/
-
- int CheckGAL(void)
- {
- int n, row;
-
-
-
- LED(ON);
- EditMode(VERIFY); /* switch GAL into edit mode */
-
- /* read logic matrix */
- for (row = 0; row <= MaxFuseAdr; row++)
- {
-
- SetRow(row); /* select row */
- STRImpuls(VERIFY_TIME); /* get bits to the shift register */
-
- for (n = 0; n < RowSize; n++)
- { /*seriell auslesen*/
-
- if (!SDOut())
- { /* read state of the SDOut output */
- ExitEditMode();
- return(1);
- }
-
- Clock(); /* shift next bit to the SDOut pin */
- }
- }
-
-
- SetRow(SigAdr); /*** read signature ***/
- STRImpuls(VERIFY_TIME);
-
- for (n = 0; n < SIG_SIZE; n++)
- {
-
- if (!SDOut())
- {
- ExitEditMode();
- return(2);
- }
-
- Clock();
- }
-
-
- /*** ACW holen ***/
- if ((GALType == GAL16V8) || (GALType == GAL20V8))
- {
- SetRow(ACW_ADR); /* select ACW */
- STRImpuls(VERIFY_TIME); /* get ACW bits */
-
- for (n = 0; n < ACW_SIZE; n++)
- {
-
- if (!SDOut())
- {
- ExitEditMode();
- return(2);
- }
-
- Clock();
-
- }
-
- }
- /*** GAL22V10 ***/
-
- if (GALType == GAL22V10)
- {
- SetARCH(1); /* select ACW */
- STRImpuls(VERIFY_TIME); /* get ACW bits */
-
- for (n = 0; n < 20; n++)
- {
- if (!SDOut())
- {
- ExitEditMode();
- return(2);
- }
-
- Clock();
- }
-
- }
-
- /*** GAL20RA10 ***/
- if (GALType == GAL20RA10)
- {
- SetARCH(1); /* select ACW */
- STRImpuls(VERIFY_TIME); /* get ACW bits */
-
- for (n = 0; n < 10; n++)
- {
- if (!SDOut())
- {
- ExitEditMode();
- return(2);
- }
-
- Clock();
- }
-
- }
-
-
- ExitEditMode();
-
- return(0); /* GAL is erased */
- }
-
-
-
-
-
- /******************************************************************************
- ** TestSecurity()
- *******************************************************************************
- ** input: none
- ** output: none
- **
- ** remarks: This function does test whether or not the security bit of the GAL
- ** is set.
- ** If the security bit is set, only the logic matrix can't be read.
- ** So if one of the cells of the logic matrix is set equal 0 then the
- ** security bit can't be set. If all cells of the logic matrix are
- ** set to 1 and one cell of the signature or the ACW is set to 0
- ** then the security bit is set. If all cells are set to 1, the GAL
- ** is erased.
- ******************************************************************************/
-
- void TestSecurity(void)
- {
- int result;
-
-
- if (GALTypeRequest(AppStrings[MSG_SEC_TEST].as_Str))
- {
-
- if (ReadGALParameter(YES)) /* get the GAL's parameters */
- return;
-
- result = CheckGAL();
-
- if (result == 2)
- TxtRequest(AppStrings[MSG_SEC_SET].as_Str,
- AppStrings[MSG_CONT_GAD].as_Str, NULL);
- else
-
- if (result == 1)
- TxtRequest(AppStrings[MSG_SEC_NOT_SET].as_Str,
- AppStrings[MSG_CONT_GAD].as_Str, NULL);
- else
- TxtRequest(AppStrings[MSG_BLANK].as_Str,
- AppStrings[MSG_CONT_GAD].as_Str, NULL);
- }
- }
-
-
-
-
-
- /******************************************************************************
- ** Compare()
- *******************************************************************************
- ** input: none
- ** output: none
- **
- ** remarks: this function does compare GAL-GAL, GAL-JEDEC, JEDEC-GAL
- ******************************************************************************/
-
- void Compare(void)
- {
- int n, row, cmptype, execute;
- int logic, acw, signature;
- UBYTE *text;
-
-
- if (!(cmptype = CompareRequester()))
- return; /* cancel selected */
-
-
- if (cmptype == 1) /* compare GAL-GAL */
- if (!GALTypeRequest(AppStrings[MSG_CMP_GALGAL].as_Str))
- return;
-
- if (cmptype == 2) /* compare GAL-JEDEC */
- if (!GALTypeRequest(AppStrings[MSG_CMP_GALJED].as_Str))
- return;
-
- if ((cmptype == 3) && (Config.GALTypeReq)) /* compare JEDEC-GAL */
- if (!GALTypeRequest(AppStrings[MSG_CMP_JEDGAL].as_Str))
- return;
-
-
-
- if (cmptype == 1 || cmptype == 2)
- {
-
- if (ReadGALParameter(YES)) /* read the GAL's parameters */
- return;
-
- PrintText(AppStrings[MSG_READING_GAL].as_Str, 1);
-
- ReadGALToJedec(); /* read GAL to the JEDEC structure */
-
- PrintText(AppStrings[MSG_LOWER_OK].as_Str, 0);
- }
-
-
-
- if (cmptype == 3)
- {
-
- if (MyFileReq(AppStrings[MSG_LOADJED].as_Str, ".jed", YES, LOAD))
- {
-
- if (GetJedec((UBYTE *)&path[0])) /* JEDEC file to structure */
- return;
-
- if (GALType != JedecGALType) /* does selected type of GAL */
- { /* and JEDEC file match */
- JedecError(25, NO);
- return;
- }
-
- }
- else
- return;
- }
-
-
- for (n = 0; n < sizeof(Jedec2); n++) /* save JEDEC structure */
- Jedec2.GALLogic[n] = Jedec.GALLogic[n];
-
-
- for (;;)
- {
-
- execute = 1;
-
- if (cmptype == 1 || cmptype == 3)
- {
-
- TxtRequest(AppStrings[MSG_GAL_TO_CMP].as_Str,
- AppStrings[MSG_CONT_GAD].as_Str, NULL);
-
- if (!ReadGALParameter(YES)) /* read the GAL's parameters */
- {
- PrintText(AppStrings[MSG_READING_GAL].as_Str, 1);
-
- ReadGALToJedec();
-
- PrintText(AppStrings[MSG_LOWER_OK].as_Str, 0);
- }
- else
- execute = 0;
- }
-
-
- if (cmptype == 2)
- {
-
- if (MyFileReq(AppStrings[MSG_LOADJED].as_Str, ".jed", YES, LOAD))
- {
-
- if (GetJedec((UBYTE *)&path[0])) /* copy JEDEC file into */
- execute = 0; /* into structure */
-
-
- if (GALType != JedecGALType) /* does the selected type of GAL */
- { /* and the the JEDEC file match? */
- JedecError(25, NO);
- execute = 0;
- }
-
- }
- else
- execute = 0;
- }
-
-
- /*** compare ***/
- if (execute)
- {
-
- logic = acw = signature = 1;
-
- /* compare logic matrizes */
- for (row = 0; row <= MaxFuseAdr; row++)
- {
-
- for (n = 0; n < RowSize; n++)
- {
-
- if (Jedec.GALLogic[row+(MaxFuseAdr+1)*n] !=
- Jedec2.GALLogic[row+(MaxFuseAdr+1)*n])
- {
- logic = 0;
- }
-
- if (!logic)
- break;
- }
-
- if (!logic)
- break;
- }
-
- /* compare signatures */
- for (n = 0; n < SIG_SIZE; n++)
- {
- if (Jedec.GALSig[n] != Jedec2.GALSig[n])
- signature = 0;
- }
-
- /* compare ACWs */
- if ((GALType == GAL16V8) || (GALType == GAL20V8))
- {
-
- if (Jedec.GALSYN != Jedec2.GALSYN)
- acw = 0;
-
- if (Jedec.GALAC0 != Jedec2.GALAC0)
- acw = 0;
-
-
- for (n = 0; n < 8; n++)
- if (Jedec.GALXOR[n] != Jedec2.GALXOR[n])
- acw = 0;
-
- for (n = 0; n < 8; n++)
- if (Jedec.GALAC1[n] != Jedec2.GALAC1[n])
- acw = 0;
-
- for (n = 0; n < PT_SIZE; n++)
- if (Jedec.GALPT[n] != Jedec2.GALPT[n])
- acw = 0;
-
- }
- else
- {
-
- for (n = 0; n < 10; n++)
- if (Jedec.GALXOR[n] != Jedec2.GALXOR[n])
- acw = 0;
-
- if (GALType == GAL22V10)
- for (n = 0; n < 10; n++)
- if (Jedec.GALS1[n] != Jedec2.GALS1[n])
- acw = 0;
-
- }
-
- /*** show result of comparing ***/
-
- if (logic && acw && signature) /* the samel? */
- text = CmpText1;
-
- if (!logic || !acw) /* not the same? */
- text = CmpText2;
-
- if (logic && acw && !signature) /* the function is the same */
- text = CmpText3; /* but the signature differs */
- }
- else
- text = CmpText4; /* canceled */
-
-
- if (!TxtRequest(text, AppStrings[MSG_CONT_GAD].as_Str,
- AppStrings[MSG_CANCEL_GAD].as_Str))
- return;
-
- }
- }
-
-
-
-
-
- /******************************************************************************
- ** PrintACW()
- *******************************************************************************
- ** input: none
- ** output: none
- **
- ** remarks: this function does read and print the architecture control word
- ** (ACW)
- ******************************************************************************/
-
- void PrintACW(void)
- {
- BYTE bit;
- int n, acw_num, xor_num, ac1_num ;
-
-
-
- acw_num = xor_num = ac1_num =0;
-
-
- if (GALTypeRequest(AppStrings[MSG_READ_ACW].as_Str))
- {
-
- if (ReadGALParameter(YES)) /* read the GAL's parameters */
- return;
-
- LED(ON); /* switch on the LED */
- EditMode(VERIFY); /* switch GAL into the edit mode */
-
- /*** 16V8, 20V8 ***/
- if ((GALType == GAL16V8) || (GALType == GAL20V8))
- {
-
- SetRow(ACW_ADR); /* select ACW */
- STRImpuls(VERIFY_TIME); /* get ACW into shift reg. */
-
- for (n = 0; n < ACW_SIZE; n++) /* read the ACW */
- {
-
- bit = (BYTE)SDOut();
- Clock();
-
- /* standard type (no A type) */
- if (!GALAType())
- {
-
- if (n < 32) /* get PT0-31 */
- {
- PTTxt[4 + acw_num] = bit + '0';
- acw_num++;
- }
-
- if (n >= 50) /* get PT32-63 */
- {
- PTTxt[4 + acw_num]=bit+'0';
- acw_num++;
- }
-
- if (n == 36) /* AC0 bit */
- ConTxt[35] = bit + '0';
-
- if (n == 45) /* SYN bit*/
- ConTxt[25] = bit + '0';
-
- if ((n >= 32) && (n <= 35)) /* 4 XOR bits */
- {
- ConTxt[8 + xor_num] = bit + '0';
- xor_num++;
- }
-
- if ((n >= 46) && (n <= 49)) /* 4 XOR bits */
- {
- ConTxt[8 + xor_num] = bit + '0';
- xor_num++;
- }
-
- if ((n >= 37) && (n <= 44)) /* AC1 bits */
- {
- AC1Txt[8 + ac1_num] = bit + '0';
- ac1_num++;
- }
-
- }
- else
- { /* A type GAL */
-
- if ((n >= 9) && (n <= 72)) /* get PT0-63 */
- {
- PTTxt[4+acw_num]=bit+'0';
- acw_num++;
- }
-
- if (n == 36) /* AC0 bit */
- ConTxt[35] = bit + '0';
-
- if (n == 77) /* SYN bit */
- ConTxt[25] = bit + '0';
-
- if (n <= 3) /* XOR bits */
- {
- ConTxt[8 + xor_num] = bit + '0';
- xor_num++;
- }
-
- if (n >= 78) /* XOR bits */
- {
- ConTxt[8 + xor_num] = bit + '0';
- xor_num++;
- }
-
- if ((n >= 5) && (n <= 8)) /* AC1 bits */
- {
- AC1Txt[8 + ac1_num] = bit + '0';
- ac1_num++;
- }
-
- if ((n >= 73) && (n <= 76)) /* AC1 bits */
- {
- AC1Txt[8 + ac1_num] = bit + '0';
- ac1_num++;
- }
- }
- }
-
- PrintText((UBYTE *)&PTTxt[0], 1);
- PrintText((UBYTE *)&ConTxt[0], 1);
- PrintText((UBYTE *)&AC1Txt[0], 1);
- }
-
-
- /*** GAL22V10 ***/
- if (GALType == GAL22V10)
- {
- SetARCH(1); /* select ACW */
- STRImpuls(VERIFY_TIME); /* get ACW into the shift register */
-
- for (n = 0; n < 10; n++)
- {
- SYN10Txt[12 + n] = SDOut() + '0'; /* get S1 */
- Clock();
-
- XOR10Txt[12 + n] = SDOut() + '0'; /* get XORs */
- Clock();
- }
-
- PrintText((UBYTE *)&XOR10Txt[0], 1);
- PrintText((UBYTE *)&SYN10Txt[0], 1);
- }
-
-
- /*** GAL20RA10 ***/
- if (GALType == GAL20RA10)
- {
- SetARCH(1); /* select ACW */
- STRImpuls(VERIFY_TIME); /* get ACW into the shift register */
-
- for (n = 0; n < 10; n++)
- {
- XOR10Txt[12 + n] = SDOut() + '0'; /* get XORs */
- Clock();
- }
-
- PrintText((UBYTE *)&XOR10Txt[0], 1);
- }
-
- ExitEditMode();
- }
- }
-
-
-
-
-
- /******************************************************************************
- ** PrintSignature()
- *******************************************************************************
- ** input: none
- ** output: none
- **
- ** remarks: this function does print the GAL's signature
- ******************************************************************************/
-
- void PrintSignature(void)
- {
- UBYTE strn[6];
- BYTE byte;
- int n;
-
-
- if (GALTypeRequest(AppStrings[MSG_READ_SIG].as_Str))
- {
-
- if (ReadGALParameter(YES)) /* get the GAL's parameters */
- return;
-
-
- LED(ON); /* switch the LED on */
-
- EditMode(VERIFY); /* switch GAL into edit mode */
-
-
- SetRow(SigAdr); /* select the signature and */
- STRImpuls(VERIFY_TIME); /* get it into the shift reg. */
-
- /*** read signature ***/
- byte = 0;
- for (n = 0; n < SIG_SIZE; n++)
- {
-
- byte |= (BYTE)SDOut(); /* eight bits -> one byte */
-
- if (!((n+1)%8))
- { /* make text */
-
- sprintf((char *)&strn[0], "%02x", (UWORD)byte);
-
- strncpy((char *)&SignatureTxt[12 + 4*((n + 1)/8 - 1)],
- (char *)&strn[0], (size_t)2);
-
- if (isprint(byte))
- SignatureTxt[47 + ((n + 1)/8 - 1)] = byte;
- else
- SignatureTxt[47 + ((n + 1)/8 - 1)] = '.';
-
- byte = 0;
- }
-
- byte <<= 1;
-
- Clock();
- }
-
- ExitEditMode(); /* exit edit mode */
-
- PrintText((UBYTE *)&SignatureTxt[0], 1); /* print signature */
- }
- }
-
-
-
-
-
- /******************************************************************************
- ** ProgJedecToGAL()
- *******************************************************************************
- ** input: mode COPYGAL: call from copy GAL function
- ** PROGGAL: call from program GAL function
- **
- ** output: 0: successful
- ** 1: programming failed because GAL is not empty
- ** 2: verify failed
- **
- ** remarks: this function does program a GAL
- ** source is the JEDEC structure
- ******************************************************************************/
-
- int ProgJedecToGAL(int mode)
- {
- int n, i, row, bit;
-
- /* execute empty test */
-
- if (((mode == COPYGAL) && Config.CopyEmptyTest) ||
- ((mode == PROGGAL) && Config.ProgEmptyTest))
- {
-
- PrintText(AppStrings[MSG_EXE_BLANK_TEST].as_Str, 1);
-
- if (CheckGAL())
- {
- PrintText(AppStrings[MSG_NOT_BLANK2].as_Str, 0);
-
- if (TxtRequest(AppStrings[MSG_NOT_BLNK_ERS].as_Str,
- AppStrings[MSG_ERASE_GAD].as_Str,
- AppStrings[MSG_CANCEL_GAD].as_Str))
- EraseIt();
- else
- return(1);
- }
- else
- PrintText(AppStrings[MSG_LOWER_OK].as_Str, 0);
-
- }
-
-
- PrintText(AppStrings[MSG_PROGING_GAL].as_Str, 1);
-
-
-
- LED(ON);
- EditMode(PROG); /* switch GAL into edit mode */
-
- /*** GAL16V8, GAL20V8 **/
-
- if (GALType == GAL16V8 || GALType == GAL20V8)
- {
- /*** program logic matrix ***/
-
- for (row = 0; row <= MaxFuseAdr; row++)
- {
- SetRow(row);
-
- for (n = 0; n < RowSize; n++)
- {
- /* set SDIn input of the GAL */
-
- SDIn((int)Jedec.GALLogic[row + (MaxFuseAdr + 1)*n]);
-
- Clock(); /* clock bit into shift register */
- }
-
- SetPV(PROG); /* set P/V to "program" */
- STRImpuls(prog_time); /* program row */
- SetPV(VERIFY); /* reset P/V */
- }
-
-
-
- SetRow(SigAdr); /*** program signature ***/
-
- for (n = 0; n < SIG_SIZE; n++)
- {
- SDIn((int)Jedec.GALSig[n]); /* set SDIn input */
- Clock(); /* clock bit into shift reg. */
- }
-
- SetPV(PROG); /* set P/V to "program" */
- STRImpuls(prog_time); /* program row */
- SetPV(VERIFY); /* reset P/V */
-
-
-
-
- SetRow(ACW_ADR); /*** program ACW ***/
-
- for (n = 0; n < ACW_SIZE; n++)
- {
-
- if (!GALAType()) /*** standard type of GAL (no A type) ***/
- {
-
- if (n <= 31) /* PT0-PT31 */
- bit = Jedec.GALPT[n];
-
- if (n >= 32 && n <= 35) /* 4 XOR bits */
- bit = Jedec.GALXOR[n - 32];
-
- if (n == 36) /* AC0 bit */
- bit = Jedec.GALAC0;
-
- if (n >= 37 && n <= 44) /* AC1 bits */
- bit = Jedec.GALAC1[n - 37];
-
- if (n == 45) /* SYN bit */
- bit = Jedec.GALSYN;
-
- if (n >= 46 && n <= 49) /* 4 XOR bits */
- bit = Jedec.GALXOR[n - 42];
-
- if (n >= 50 && n <= 81) /* PT32-PT63 */
- bit = Jedec.GALPT[n - 18];
-
- }
- else
- { /*** A type GAL ***/
-
- if (n <= 3) /* 4 XOR bits */
- bit = Jedec.GALXOR[n];
-
- if (n == 4) /* AC0 bit */
- bit = Jedec.GALAC0;
-
- if (n >= 5 && n <= 8) /* AC1 bits */
- bit = Jedec.GALAC1[n - 5];
-
- if (n >= 9 && n <= 72) /* PT0-PT63 */
- bit = Jedec.GALPT[n - 9];
-
- if (n >= 73 && n <= 76) /* AC1 bits */
- bit = Jedec.GALAC1[n-69];
-
- if (n == 77) /* SYN bit */
- bit = Jedec.GALSYN;
-
- if (n >= 78) /* XOR bits */
- bit = Jedec.GALXOR[n-74];
-
- }
-
- SDIn((int)bit); /* set SDIn input */
- Clock(); /* clock bit into shift register */
- }
-
- SetPV(PROG); /* set P/V to "program" */
- STRImpuls(prog_time); /* program row */
- SetPV(VERIFY); /* reset P/V */
-
-
- }
- else
- { /*** GAL20RA10, GAL22V10 ***/
-
- /*** program logic matrix ***/
- for (row = 0; row <= MaxFuseAdr; row++)
- {
- for (n = 0; n < RowSize; n++)
- {
- /* set SDIn input */
- SDIn((int)Jedec.GALLogic[row + (MaxFuseAdr + 1)*n]);
-
- Clock(); /* clock bit into shift register */
- }
-
- SetRow(row);
- SDIn(0);
-
- SetPV(PROG); /* set P/V to "program" */
- STRImpuls(prog_time); /* program row */
- SetPV(VERIFY); /* reset P/V */
- }
-
- /*** program signature ***/
-
- for (n = 0; n < SIG_SIZE; n++)
- {
- SDIn((int)Jedec.GALSig[n]); /* set SDIn input */
- Clock(); /* clock bit into shift reg. */
- }
-
-
- for (n = 0; n < 132 - SIG_SIZE; n++)
- { /* clock missing bits */
- SDIn(1);
- Clock();
- }
-
- SetRow(SigAdr);
- SDIn(0);
-
- SetPV(PROG); /* set P/V to "program" */
- STRImpuls(prog_time); /* program row */
- SetPV(VERIFY); /* reset P/V */
-
-
- /*** program ACW ***/
- SetARCH(1); /* select ACW array */
-
- for (n = 0; n < 10; n++)
- {
- if (GALType == GAL22V10) /* if 22V10, first SYN */
- {
-
- SDIn((int)Jedec.GALS1[n]);
- Clock();
- }
-
- SDIn((int)Jedec.GALXOR[n]); /* clock XOR */
- Clock();
- }
-
- SDIn(0);
-
- SetPV(PROG); /* set P/V to "program" */
- STRImpuls(prog_time); /* program row */
- SetPV(VERIFY); /* reset P/V */
-
- }
-
- ExitEditMode(); /* exit edit mode */
-
- PrintText(AppStrings[MSG_LOWER_OK].as_Str, 0); /* print o.k. */
-
-
-
- /*** execute verify ***/
-
- if (((mode == COPYGAL) && Config.CopyVerify) ||
- ((mode == PROGGAL) && Config.ProgVerify))
- {
-
- PrintText(AppStrings[MSG_VERIFYING].as_Str, 1);
-
- for (n = 0; n < sizeof(Jedec2); n++) /* save JEDEC structure */
- Jedec2.GALLogic[n] = Jedec.GALLogic[n];
-
- ReadGALToJedec(); /* read GAL after programming */
-
- for (i = 0; i < sizeof(Jedec); i++) /* compare JEDEC structures */
- {
- if (Jedec.GALLogic[i] != Jedec2.GALLogic[i])
- {
- TxtRequest(AppStrings[MSG_VERFAILED].as_Str,
- AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
-
- PrintText(AppStrings[MSG_FAILED].as_Str, 0);
-
- /* restore JEDEC structure */
- for (i = 0; i < sizeof(Jedec2); i++)
- Jedec.GALLogic[i] = Jedec2.GALLogic[i];
-
- return(2);
- }
- }
-
- for (n = 0; n < sizeof(Jedec2); n++) /* restore JEDEC structure */
- Jedec.GALLogic[n] = Jedec2.GALLogic[n];
-
- PrintText(AppStrings[MSG_LOWER_OK].as_Str, 0);
- }
-
- return(0);
- }
-
-
-
-
-
- /******************************************************************************
- ** ReadGALToJedec()
- *******************************************************************************
- ** input: none but global data MaxFuseAdr, SigAdr and RowSize must be
- ** output: none
- **
- ** remarks: This function does read a GAL and stores the data in the
- ** JEDEC structure.
- ******************************************************************************/
-
- void ReadGALToJedec(void)
- {
- int n, row;
- BYTE bit;
-
-
- LED(ON);
- EditMode(VERIFY); /* switch GAL into verify mode */
-
- /*** read logic matrix ***/
- for (row = 0; row <= MaxFuseAdr; row++)
- {
- SetRow(row); /* set row */
-
- STRImpuls(VERIFY_TIME); /* clock bits into shift register */
-
- for (n = 0; n < RowSize; n++) /* read bits sequentially */
- {
- Jedec.GALLogic[row + (MaxFuseAdr + 1)*n] = (BYTE)SDOut();
-
- Clock(); /* shift next bit to SDOut */
- }
- }
-
-
-
- SetRow(SigAdr); /*** read signature ***/
- STRImpuls(VERIFY_TIME);
-
- for (n = 0; n < SIG_SIZE; n++)
- {
- Jedec.GALSig[n] = (BYTE)SDOut();
- Clock();
- }
-
- /*** read ACW ***/
-
- if (GALType == GAL16V8 || GALType == GAL20V8)
- {
-
- SetRow(ACW_ADR);
- STRImpuls(VERIFY_TIME); /* get bits into shift register */
-
- for (n = 0; n < ACW_SIZE; n++)
- {
-
- bit = (BYTE)SDOut();
- Clock();
-
- if (!GALAType()) /*** standard GAL type ***/
- {
-
- if (n <= 31)
- Jedec.GALPT[n] = bit; /* PT0-PT31 */
-
- if (n >= 32 && n <= 35) /* 4 XOR bits */
- Jedec.GALXOR[n - 32] = bit;
-
- if (n == 36) /* AC0 bit */
- Jedec.GALAC0 = bit;
-
- if (n >= 37 && n <= 44) /* AC1 bits */
- Jedec.GALAC1[n - 37] = bit;
-
- if (n == 45) /* SYN bit */
- Jedec.GALSYN=bit;
-
- if ((n >= 46) && (n <= 49)) /* 4 XOR bits */
- Jedec.GALXOR[n - 42] = bit;
-
- if (n >= 50 && n <= 81) /* PT32-PT63 */
- Jedec.GALPT[n - 18] = bit;
-
- }
- else
- { /*** A type GAL ***/
-
- if (n <= 3) /* 4 XOR bits 19-16 */
- Jedec.GALXOR[n] = bit;
-
- if (n == 4) /* AC0 bit */
- Jedec.GALAC0 = bit;
-
- if (n >= 5 && n <= 8) /* AC1 bits */
- Jedec.GALAC1[n - 5] = bit;
-
- if (n >= 9 && n <= 72) /* PT0-PT63 */
- Jedec.GALPT[n - 9] = bit;
-
- if (n == 77) /* SYN bit */
- Jedec.GALSYN = bit;
-
- if (n >= 73 && n <= 76) /* AC1 bits */
- Jedec.GALAC1[n - 69] = bit;
-
- if (n >= 78) /* XOR bits */
- Jedec.GALXOR[n - 74] = bit;
- }
- }
- }
-
- /*** 22V10 ***/
- if (GALType == GAL22V10)
- {
- SetARCH(1); /* select ACW */
- STRImpuls(VERIFY_TIME);
-
- for (n = 0; n < 10; n++)
- {
- Jedec.GALS1[n] = (BYTE)SDOut(); /* get S1x */
- Clock();
-
- Jedec.GALXOR[n] = (BYTE)SDOut(); /* get XORx */
- Clock();
- }
- }
-
- /*** 20RA10 ***/
- if (GALType == GAL20RA10)
- {
- SetARCH(1); /* select ACW */
- STRImpuls(VERIFY_TIME);
-
- for (n = 0; n < 10; n++)
- {
- Jedec.GALXOR[n] = (BYTE)SDOut(); /* get XORx */
- Clock();
- }
- }
-
- ExitEditMode();
- }
-
-
-
-
-
- /******************************************************************************
- ** SetSecurity()
- *******************************************************************************
- ** input: flag 0: call from the program GAL function because of a set
- ** JEDEC security bit
- ** 1: call from any other function
- **
- ** output: none
- **
- ** remarks: this function does set the GAL's security bit
- ******************************************************************************/
-
- void SetSecurity(int flag)
- {
- int result;
-
-
- if (flag)
- result = GALTypeRequest(AppStrings[MSG_SET_SEC].as_Str);
- else
- result = TxtRequest(AppStrings[MSG_SET_SEC].as_Str,
- AppStrings[MSG_CONT_GAD].as_Str,
- AppStrings[MSG_CANCEL_GAD].as_Str);
-
-
- if (result)
- {
-
- if (flag)
- if (ReadGALParameter(YES)) /* get the GAL's parameters */
- return;
-
- LED(ON);
-
- EditMode(PROG);
-
- SetRow(SECURITY_ADR); /* select security fuse */
-
- SetPV(PROG); /* set P/V to "program" */
- STRImpuls(prog_time); /* program row */
- SetPV(VERIFY); /* reset P/V */
-
- ExitEditMode();
-
- if (flag)
- TxtRequest(AppStrings[MSG_SEC_IS_SET].as_Str,
- AppStrings[MSG_CONT_GAD].as_Str, NULL);
- }
- }
-
-
-
-
-
- /******************************************************************************
- ** Loeschen() (means Erase())
- *******************************************************************************
- ** input: none
- ** output: none
- **
- ** remarks: This function does erase a GAL.
- ******************************************************************************/
-
- void Loeschen(void)
- {
- int result;
-
-
- if (GALTypeRequest(AppStrings[MSG_ERASE_GAL].as_Str))
- {
-
- if (ReadGALParameter(YES))
- return;
-
- EraseIt();
-
- if (Config.EraseEmptyTest) /* test whether or not the */
- { /* GAL is erased? */
-
- PrintText(AppStrings[MSG_GAL_ERASED].as_Str, 1);
-
- PrintText(AppStrings[MSG_EXE_BLANK_TEST].as_Str, 1);
-
- result = CheckGAL();
-
- PrintText(AppStrings[MSG_READY].as_Str, 0);
-
- if (result)
- {
- TxtRequest(AppStrings[MSG_ERASE_FAILED].as_Str,
- AppStrings[MSG_CANCEL_GAD].as_Str, NULL);
- return;
- }
- }
-
- TxtRequest(AppStrings[MSG_ERASED].as_Str,
- AppStrings[MSG_CONT_GAD].as_Str, NULL);
- }
- }
-
-
-
-
-
- /******************************************************************************
- ** EraseIt()
- *******************************************************************************
- ** input: none
- ** output: none
- **
- ** remarks: This function does erase a GAL.
- ** ReadGALParameter should be called before calling this function!
- ******************************************************************************/
-
- void EraseIt(void)
- {
-
- LED(ON);
-
- EditMode(PROG);
-
-
- if (GALType == GAL16V8 || GALType == GAL20V8)
- {
- SetRow(ERASE_ADR);
- SDIn(1);
-
- SetPV(PROG); /* set P/V to "program" */
- STRImpuls(bulk_time); /* execute bulk erase */
- SetPV(VERIFY); /* reset P/V */
- }
-
-
- if (GALType == GAL22V10)
- {
- SDIn(1);
- SetPV(PROG);
- SetANDBE(1);
- SetARCH(1);
- SetBE(1);
- SetCLR(1);
- SetERASE(1);
-
- STRImpuls(bulk_time); /* execute bulk erase */
-
- SetPV(VERIFY);
- SetANDBE(0);
- SetARCH(0);
- SetBE(0);
- SetCLR(0);
- SetERASE(0);
- }
-
-
- if (GALType == GAL20RA10)
- {
- SDIn(1);
- SetPV(PROG);
- SetPESSAVE(1);
- SetARCH(1);
- SetBE(1);
- SetCLR(1);
-
- STRImpuls(bulk_time); /* erase ACW */
-
- SetARCH(0);
-
- STRImpuls(bulk_time); /* erase AND array */
-
- SetPV(VERIFY);
- SetPESSAVE(0);
- SetBE(0);
- SetCLR(0);
- }
-
-
- ExitEditMode();
-
- }
-
-